
SELECT JobTitle, LastName, VacationHours,
       FIRST_VALUE(LastName) OVER (PARTITION BY JobTitle  -- Partitioning the data by job title
                                   ORDER BY VacationHours ASC  -- Ordering the data by vacation hours in ascending order
                                   ROWS UNBOUNDED PRECEDING  -- Specifying the window frame to include all preceding rows within the partition
                                  ) AS FewestVacationHours  -- Calculating the last name of the employee with the fewest vacation hours
FROM HumanResources.Employee AS e
INNER JOIN Person.Person AS p
    ON e.BusinessEntityID = p.BusinessEntityID
ORDER BY JobTitle;
